package com.jackiechancinema.ssm.controller;

import com.jackiechancinema.ssm.bo.DepartmentBo;
import com.jackiechancinema.ssm.bo.WorkerBo;
import com.jackiechancinema.ssm.entity.Worker;
import com.jackiechancinema.ssm.service.Inte.WorkerService;
import com.jackiechancinema.ssm.vo.PageVo;
import com.jackiechancinema.ssm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;


@RestController
@RequestMapping("/api/worker/")
public class WorkerController {

    @Autowired
    private WorkerService workerService;

    /**
     * 新增
     * @param worker
     * @return
     */
    @RequestMapping("insertWork")
    public R insertWork(Worker worker){
        return workerService.insertWork(worker);
    }
    @RequestMapping("insertBatch")
    public R insertBatch(MultipartFile file){
        System.out.println("enter1");
        return workerService.insertBatch(file);
    }
    /**
     * 修改
     * @param worker
     * @return
     */
    @PostMapping("updateWork")
    public R updateWork(Worker worker){
        return workerService.updateWork(worker);
    }

    /**
     * 删除
     * @param work_id
     * @return
     */
    @PostMapping("deleteWork")
    public R deleteWork(int work_id){
        return workerService.deleteWork(work_id);
    }

    /**
     * 查询
     * @param workerBo
     * @return
     */
    @GetMapping("selectWork")
    public PageVo<Worker> selectWork(WorkerBo workerBo){
        return workerService.page2(workerBo);
    }
    /**
     * 下载，导出excel表格
     * @param bo
     * @param response
     */
    @GetMapping("download")
    public void download(WorkerBo bo, HttpServletResponse response){
        workerService.exportExcel(bo,response);
    }
}
